"""
认证相关的Pydantic模型
"""

from typing import Optional

from pydantic import ConfigDict, Field

from app.schemas.base import BaseSchema


class Token(BaseSchema):
    """Token响应模型"""

    token_type: str = Field("Bearer", alias="tokenType", description="token类型")
    access_token: str = Field(..., alias="accessToken", description="访问token")
    refresh_token: str = Field(..., alias="refreshToken", description="刷新token")
    expires_in: Optional[int] = Field(None, alias="expiresIn", description="过期时间（秒）")


class Captcha(BaseSchema):
    """
    验证码响应Schema

    属性:
        captcha_key: 验证码键，用于后续验证
        captcha_base64: Base64编码的验证码图片
    """

    captcha_key: str = Field(..., alias="captchaKey", description="验证码键，用于后续验证")
    captcha_base64: str = Field(..., alias="captchaBase64", description="Base64编码的验证码图片")

    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "captchaKey": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
                "captchaBase64": "...",
            }
        },
    )


class TokenData(BaseSchema):
    """Token数据模型"""

    username: Optional[str] = None


class LoginResponse(BaseSchema):
    """登录响应模型"""

    user_id: int = Field(..., alias="userId", description="用户ID")
    username: str = Field(..., alias="userName", description="用户名")
    nickname: str = Field(..., alias="nickName", description="昵称")
    mobile: str = Field(..., description="手机号")
    token: Token = Field(..., description="令牌信息")


class RefreshTokenRequest(BaseSchema):
    """刷新token请求模型"""

    refresh_token: str = Field(..., alias="refreshToken", description="刷新token")


class RefreshTokenResponse(BaseSchema):
    """刷新token响应模型"""

    access_token: str = Field(..., alias="accessToken", description="访问token")
    token_type: str = Field("bearer", alias="tokenType", description="token类型")
